package com.jiudaoliu.homeprototype.controller;

import com.jiudaoliu.homeprototype.POJO.VO.CommonVO;
import com.jiudaoliu.homeprototype.entity.SourceInfoEntity;
import com.jiudaoliu.homeprototype.enums.STATUS_ENUM;
import com.jiudaoliu.homeprototype.service.SourceInfoServie;
import com.jiudaoliu.homeprototype.service.SourceTypeServie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Package com.jiudaoliu.homeprototype.controller
 * @Description:
 * @Author 陈建
 * @Create: 2018-09-20 13:38
 * @Version 1.0
 * @Update: message
 */
@RestController
@RequestMapping(value = "/source")
public class SourceController {
    @Autowired
    private SourceInfoServie sourceInfoServieImpl;

    @Autowired
    private SourceTypeServie sourceTypeServieImpl;

    @GetMapping(value = "/findbymodelid/{status}/{id}")
    public CommonVO findByModelId(@PathVariable String status, @PathVariable Long id) {
        //status默认为正常使用的状态(),只有匹配到all的时候才能查询所有的数据
        if (null != status && STATUS_ENUM.STATUS_ALL.getStatus().equals(status)) {
            return sourceInfoServieImpl.findAllByModelid(id);
        }
        return sourceInfoServieImpl.findByStatusAndModelid(STATUS_ENUM.STATUS_USE.getStatus(), id);
    }

    @PostMapping(value = "/add")
    public CommonVO addNewSources(SourceInfoEntity sourceInfo) {

        return sourceInfoServieImpl.add(sourceInfo);
    }

    @GetMapping(value = "/find/type/all")
    public CommonVO findAllType() {
        return sourceTypeServieImpl.findAllType();
    }

    @GetMapping(value = "/findone/{id}")
    public CommonVO findOne(@PathVariable Long id) {
        return sourceInfoServieImpl.findById(id);
    }
}
